package com.lg.online_shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lg.online_shop.entity.Cart;
import com.lg.online_shop.vo.CartInfo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CartMapper extends BaseMapper<Cart> {
//    联表查询购物车列表
    @Select("SELECT c.id as cart_id,g_name,g_price,g_cover_url,count,size_id,color_id FROM cart c JOIN good g ON c.g_id = g.id JOIN user u ON c.u_id = u.id where u.id = #{userId};")
    List<CartInfo> selectCartInfoList(Long userId);

//    查询是否存在
//    @Select("SELECT * FROM cart WHERE u_id = #{uId} AND g_id = #{gId}")
//    Cart selectOne(Cart cart);

//    修改购物车商品数量
    @Select("UPDATE cart SET count = #{count} WHERE id = #{id}")
    void updateCount(Cart cart);

//    添加商品
    @Select("INSERT INTO cart(g_id, u_id,size_id,color_id, count) VALUES(#{gId}, #{uId},#{sizeId},#{colorId},#{count})")
    void insertCart(Cart cart);

//    查找是否存在
    @Select("SELECT * FROM cart WHERE u_id = #{uId} AND g_id = #{gId} AND size_id = #{sizeId} AND color_id = #{colorId}")
    Cart findOne(Cart cart);


//    获取购物车
    @Select("select  * from cart where u_id = #{uId}")
    List<Cart> selectByUId(Long uId);
}